<template>
    <section class="modlude">
        <!-- 导航栏 -->
        <p class="margintop"></p>
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="formSearch" class="gridContt">
                <el-form class="form_inline " :inline="true">
                    <el-form-item label="所属项目" size="small">
                        <el-select v-model="formSearch.xqId" placeholder="请选择区域">
                            <el-option v-for="(item,index) in xqTree1" :label="item.name" :value="item.id" :key="index">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item size="small" label="分类">
                        <el-input placeholder="请选择" v-model="formSearch.goodsBarCode" size='small'></el-input>
                    </el-form-item>
                    <el-form-item size="small" label="设备名称">
                        <el-input placeholder="请输入" v-model="formSearch.name" size='small'></el-input>
                    </el-form-item>
                    <el-button type="primary" size='small'
                        @click="getlist">查 询</el-button>
                    <el-button type="primary" size='small'
                        @click="xinzeng">新 增</el-button>
                    <el-button size="small" type="danger"
                        @click="deleInfor(false)">批量删除</el-button>
                </el-form>
            </el-form>
        </el-col>

        <!-- 列表部分 -->
        <el-table :data="formData" stripe @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <!-- <el-table-column prop="name" label="所属仓库">
              </el-table-column> -->
            <el-table-column prop="xqName" label="所属项目">
            </el-table-column>
            <el-table-column prop="number" label="设备编号">
            </el-table-column>
            <el-table-column prop="classifyName" label="类别">
            </el-table-column>
            <el-table-column prop="name" label="设备名称">
            </el-table-column>
            <el-table-column prop="model" label="设备型号">
            </el-table-column>
            <el-table-column prop="principal" label="设备负责人">
            </el-table-column>
            <el-table-column prop="installationDate" label="安装日期">
            </el-table-column>
            <!-- <el-table-column prop="leastKeep" label="报警">
            </el-table-column>
            <el-table-column prop="leastKeep" label="状态">
            </el-table-column> -->
            <el-table-column label="操作" fixed="right" width=350>
                <template slot-scope="scope">
                    <el-button size="small" type="warning"
                        @click="updatewllist(scope.row,2)">修改</el-button>
                    <el-button size="small" type="danger"
                        @click="deleInfor(scope.row.id)">删除</el-button>
                    <el-button size="small"
                        @click="sbcode(scope.row.id,scope.row)">设备二维码</el-button>
                    <el-button size="small"
                        @click="updatewllist(scope.row,3)">详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <paging @changePage='handleCurrentPage' :get-total='total'></paging>
        <!-- 批量删除，下标页码 -->
        <!-- <el-col :span="24" class="paginationt">
              <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="10" :page-count="total" class="pagination">
              </el-pagination>
          </el-col> -->

        <!-- 添加列表 -->
        <el-dialog :title="Addoredit==1?'设备新增':Addoredit==2?'修改':'详情'" width="40%" :visible.sync="adddialog"
            @close="closeform" :close-on-click-modal="false">
            <el-form label-width="120px" :inline="true" :model='formPush' ref="addsbform">
                <!-- <el-form-item label="所属仓库">
                <el-input v-model="formPush.inStore" auto-complete="off" ></el-input>
              </el-form-item>
          <el-form-item label="物料条码">
            <el-input v-model="formPush.cangku" auto-complete="off" ></el-input>
          </el-form-item> -->
                <el-form-item label="选择项目" size="small" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }" prop="xqId">
                    <el-select v-model="formPush.xqId" placeholder="请选择区域" @change="xqidtosbtype">
                        <el-option v-for="(item,index) in xqTree1" :label="item.name" :value="item.id" :key="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="设备编号" size="small" prop="number" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.number" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="设备名称" size="small" prop="name" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.name" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="类别" size="small" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <!-- <el-select v-model="formPush.classifyId" placeholder="请选择类别">
                        <el-option v-for="(item,index) in sbtypeTree" :label="item.name" :value="item.id" :key="index">
                        </el-option>
                    </el-select> -->
                    <el-cascader ref="cascader" :show-all-levels="false" v-model="option1" :options="sbtypeTree"
                        :props="defaultProps2" @change="wptypeChange" clearable>
                    </el-cascader>
                    <!-- <el-input v-model.number="formPush.classifyId" auto-complete="off"></el-input> -->
                </el-form-item>

                <el-form-item label="设备厂家" size="small" prop="vender" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.vender" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="设备型号" size="small" prop="model" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.model" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="供应商联系人" size="small" prop="supplierName" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.supplierName" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="供应商联系方式" size="small" prop="supplierPhone" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.supplierPhone" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="安装日期" size="small" prop="installationDate" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">

                    <el-date-picker v-model="formPush.installationDate" type="datetime" placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="安装位置" size="small" prop="namehouse" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.namehouse" disabled auto-complete="off">
                        <el-button style="padding-right:10px" slot="suffix" type="text" @click="getsectionList">选择
                        </el-button>
                    </el-input>
                </el-form-item>
                <el-form-item label="开始使用时间" size="small" prop="startTime" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-date-picker v-model="formPush.startTime" type="datetime" placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="报废日期" size="small" prop="scrapTime" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-date-picker v-model="formPush.scrapTime" type="datetime" placeholder="选择日期时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="设备负责人" size="small" prop="principal" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-input v-model="formPush.principal" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="备注" size="small">
                    <el-input v-model="formPush.remark" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="设备图片" prop="" size="small" :rules="{
                    required: true, message: '该项不能为空', trigger: 'change'
                }">
                    <el-upload ref="addUpdata" class="avatar-uploader" action="/api/v1.0/file/upload/file"
                        :show-file-list="false" :headers='headers' :on-change="onChange"
                        :on-success="handleAvatarSuccess">
                        <img v-if="imageUrl" :src="imageUrl" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button size="" v-if="Addoredit == 3" @click="adddialog = false">关 闭</el-button>
                <el-button v-if="Addoredit == 1 || Addoredit == 2" type="primary" @click="addList">提交</el-button>
            </div>
            <!-- 选择位置（区域、房间） -->
            <el-dialog width="30%" title="选择位置(区域或房间)" :visible.sync="selecthouse" append-to-body @close="closeqyfj"
                :close-on-click-modal="false">
                <el-form :inline="true" :model="formsectionData" class="form_inline">
                    <el-form-item label="区域名称" size="small">
                        <el-input v-model="formsectionData.name" placeholder="请输入区域名称"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button size="small" @click="getsectionList">查 询</el-button>
                    </el-form-item>
                </el-form>
                <el-table @row-click="rowClick" :data="sectionData" style="width: 100%">
                    <el-table-column width="25">
                        <template slot-scope="scope">
                            <el-radio
                                @change='locationdform.location = scope.row.id,formPush.sectionId = scope.row.id,formPush.houseId ="",formPush.namehouse = scope.row.name'
                                v-model="locationdform.location" :label="scope.row.id" style="color:transparent;">
                            </el-radio>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" label="区域名称"></el-table-column>
                    <el-table-column prop="xqName" label="所属区域"></el-table-column>
                </el-table>
                <div class="pagination">
                    <el-pagination layout="prev, pager, next" prev-text="上一页" next-text="下一页"
                        @current-change="handleCurrentPage1" :page-size="5" :total="total1">
                    </el-pagination>
                </div>
                <el-form :inline="true" :model="formhouseData" class="form_inline">
                    <el-form-item label="房间名称" size="small">
                        <el-input v-model="formhouseData.name" placeholder="请输入房间名称"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button size="small" @click="gethouselist">查 询</el-button>
                    </el-form-item>
                </el-form>
                <el-table @row-click="rowhouseClick" :data="houseData" style="width: 100%">
                    <el-table-column width="25">
                        <template slot-scope="scope">
                            <el-radio
                                @change='locationdform.location = scope.row.id,formPush.houseId =scope.row.id,formPush.sectionId = scope.row.sectionId,formPush.namehouse = scope.row.name'
                                v-model="locationdform.location" :label="scope.row.id" style="color:transparent;">
                            </el-radio>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" label="房间名称"></el-table-column>
                    <el-table-column prop="sectionName" label="所属区域"></el-table-column>
                </el-table>
                <div class="pagination">
                    <el-pagination layout="prev, pager, next" prev-text="上一页" next-text="下一页"
                        @current-change="handleCurrentPage2" :page-size="5" :total="total2">
                    </el-pagination>
                </div>
                <div slot="footer" class="dialog-footer">
                    <el-button size="medium " @click="selecthouse = false">确 定</el-button>
                </div>

            </el-dialog>

        </el-dialog>

        <!-- 二维码 -->
        <el-dialog title="设备二维码" :visible.sync="codeShow" width="25%" :close-on-click-modal="false">
            <div class="shouquan" id='printBill' ref="shouquan1">
                <div>设备名称：{{ewmwz.name}}</div>
                <div class="codediv">
                    <div class="qrcode" ref="qrCodeUrl"></div>
                </div>
                <!-- <div>位置：{{ewmwz.sectionName}}{{ewmwz.houseName==null?'':'-'+ewmwz.houseName}}</div> -->
                <div>扫码获取设备详细信息</div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button size="medium " @click="codeShow = false">关 闭</el-button>
                <el-button size="medium " @click="printContext">打印</el-button>
                <!-- updataImg(1) -->
            </div>
        </el-dialog>

    </section>
</template>
<script>
    import paging from '../../components/paging'
    import { updDeviceOperations, deleteDeviceOperations, addDeviceOperations, getDevOperationsList, orgTree, storeGoodsadd, sectionList, houseList, xqSelectList, storeGoodsUnitselect, getDeviceClassifyXq } from '../../url/api'
    export default {
        data() {
            return {
                Addoredit: 1,
                canvas: {
                    width: document.body.clientWidth - 30,
                    height: document.body.clientHeight - 30
                },
                codeShow: false,
                headers: {
                    Authorization: sessionStorage.getItem('Authorization'),
                    token: sessionStorage.getItem('token')
                },
                selecthouse: false,//房间选择窗口
                formsectionData: {
                    current: 1,
                    pid: 0,
                    size: 5
                },
                formhouseData: {
                    current: 1,
                    size: 5
                },
                locationdform: {},
                houseData: [],//房间数据
                sectionData: [],
                total1: 0,//数据总数
                total2: 0,//数据总数
                // 表单校验规则
                xcdRules: {
                },
                formSearch: {//查询条件
                    current: 1,
                    size: 10
                },
                total: 0,//数据总数
                adddialog: false,
                addForm: {},
                formData: [],
                formPush: {},
                xqTree1: [],
                dataTree: [],
                option1: [],
                sbtypeTree: [],
                defaultProps: {
                    children: 'children',
                    label: 'name',
                    value: 'id',
                    expandTrigger: 'hover', checkStrictly: true
                },
                defaultProps2: {
                    children: 'children',
                    label: 'name',
                    value: 'id',
                    expandTrigger: 'hover', checkStrictly: true
                },
                parentId: '',//父id
                zijiid: '',
                imageUrl: '',
                deleBatch: '',
                ewmwz: {},
            }
        },
        methods: {

            handleSelectionChange(val, self) {//多选
                this.deleBatch = val
                //console.log(this.deleBatch)
            },

            xinzeng() {
                this.adddialog = true
                console.log("新增打开");
            },

            closeform() {
                //this.adddialog = false
                this.formPush = {
                    xqId: '',
                    vender: '',
                    supplierPhone: '',
                    supplierName: '',
                    startTime: '',
                    scrapTime: '',
                    remark: '',
                    principal: '',
                    picture: '',
                    number: '',
                    name: '',
                    model: '',
                    installationDate: '',
                    classifyId: '',
                    namehouse: '',
                }
                this.Addoredit = 1
                this.imageUrl = ''
                this.$refs.addsbform.resetFields();
                console.log(this.formPush);
                this.option1 = []
                // console.log("AAAAAAAAAA");

            },

            // 图片上传
            onChange(file, fileList) {
                console.log(file, fileList)
                this.imageUrl = URL.createObjectURL(file.raw);
            },
            handleAvatarSuccess(res, file) {//添加头像上传成功
                console.log(res, file)
                this.imageUrl = URL.createObjectURL(file.raw);
                if (res.ok) {
                    this.formPush.picture = res.data[0]
                }
            },
            //图片上传end


            sbcode(id, row) {
                // console.log(id);
                let text = '' + id;
                this.ewmwz = row;
                this.codeShow = true;
                setTimeout(() => {
                    this.creatQrCode(text);
                }, 100)

            },
            creatQrCode(text) {
                // console.log(text);
                if (this.qrcode) {
                    this.qrcode.clear(); // 清除代码
                    this.qrcode.makeCode(text); // 生成另外一个二维码
                    return
                }
                this.qrcode = new QRCode(this.$refs.qrCodeUrl, {
                    text: text,
                    width: 150,
                    height: 150,
                    colorDark: '#000000',
                    colorLight: '#ffffff',
                    correctLevel: QRCode.CorrectLevel.H
                })
            },
            //打印
            printContext() {
                const style = '@media print { .shouquan{ text-align: center;color: black;background: #fff;margin-left:20%} .codediv {margin: 20px 0;text-align: center; } ';

                printJS({
                    printable: 'printBill', //shouquan打印区域
                    type: 'html',  //打印类型html，还可以是json，image等，详细写法见官网
                    //targetStyles: ['*'],  //css样式，写成*代表打印样式完全继承你页面的样式
                    style: style
                    //  maxWidth:'800px'  //打印界面最大宽度，适当调整可以解决打印页面过宽，显示不完整的问题
                })
            },

            deleInfor(ids) {

                let arrId = []
                if (ids) {
                    arrId.push(ids)
                } else {
                    if (this.deleBatch.length != 0) {
                        this.deleBatch.filter((item) => {
                            arrId.push(item.id)
                            return item
                        })
                    } else {
                        this.$message("请勾选要删除的数据！")
                        return
                    }
                }
                this.$confirm("确定要删除吗？", '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteDeviceOperations(arrId).then((res) => {
                        ////console.log("删除", res)
                        if (res.data.ok) {
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            this.getInit()
                            this.formPush = {}
                        } else {
                            this.$message('删除失败')
                        }
                    })

                }).catch(() => {

                });

            },


            xqidtosbtype(data) {
                let params = {
                    xqId: data
                }

                getDeviceClassifyXq(params).then((res) => {//设备类别
                    ////console.log(res)
                    if (res.data.ok) {
                        this.sbtypeTree = res.data.data
                    }
                    //console.log("this.sbtypeTree", this.sbtypeTree)
                })
            },




            // let treeDef = this.get_OrganizationId2(
            // 	"32321",
            //   this.treeData,
            //   "deptCascader"
            // );

            //多联级类型数据回显
            //
            get_OrganizationId2(ids, treeData, refsName) {
                var _this = this;
                /*
                  ids 后端返回单选或者多选 的id数组(单选：string,多选为：array)
                  treeData 整个树状数据
                  refsName 级联组件ref值
                 */
                //console.log(refsName);
                let checkdeType = false; //取 多选true 单选false
                let ValueName = "id"; //取 value 字段
                let childrenName = "children"; //取 children 字段
                let newModel = []; //赋值默认选中数组
                let itemIds = []; //单条id 回显数组
                let returnActive = false; //是否找着对应部门（数据返回单个）
                let lastRow = lastVerify(treeData); //获取最后遍历的id
                if (!checkdeType && !(ids instanceof Array)) ids = [ids]; // 单选 ids 格式转换

                for (let i = 0; i < ids.length; i++) {
                    itemIds = [];
                    returnActive = false;
                    filterChild(ids[i], [], treeData);
                    if (itemIds.length > 0) {
                        if (checkdeType) {
                            //多选
                            newModel.push(itemIds);
                        } else {
                            //单选
                            newModel = itemIds;
                        }
                    }
                }
                /* 数据过滤解释 回显数据绑定 */
                // this.$nextTick(() => {
                //     this.dataForm.defDeptIds = newModel;
                // });
                return newModel;
                /* 过滤子级 */
                function filterChild(id, parentIds, selfArr) {
                    for (let j = 0; j < selfArr.length; j++) {
                        if (returnActive) return false;
                        returnActive = selfArr[j][ValueName] == id;
                        if (returnActive) {
                            parentIds.push(selfArr[j][ValueName]);
                            itemIds = parentIds;
                            return false;
                        } else if (
                            selfArr[j][childrenName] &&
                            selfArr[j][childrenName].length > 0
                        ) {
                            parentIds.push(selfArr[j][ValueName]);
                            filterChild(id, parentIds, selfArr[j][childrenName]);
                        } else {
                            /* 最后一级的最后一个判断 */
                            if (lastRow && selfArr[j][ValueName] == lastRow) {
                                //console.log("未找到对应部门!", id);
                                parentIds = [];
                                itemIds = parentIds;
                                return false;
                            }
                        }
                        /* 循环结束 未找着父级 */
                        if (j == selfArr.length - 1 && !returnActive) {
                            parentIds.splice(parentIds.length - 1, 1);
                        }
                    }
                }

                /* 是否最子级判断 */
                function lastVerify(allTreeData = treeData) {
                    if (allTreeData && allTreeData.length > 0) {
                        if (
                            allTreeData[allTreeData.length - 1][childrenName] &&
                            allTreeData[allTreeData.length - 1][childrenName].length > 0
                        ) {
                            return lastVerify(allTreeData[allTreeData.length - 1][childrenName]);
                        } else {
                            return lastVerify(allTreeData[allTreeData.length - 1]);
                        }
                    } else {
                        if (allTreeData[ValueName]) return allTreeData[ValueName];
                        return false;
                    }
                }
            },

            getsectionList() {
                if (this.formPush.xqId) {
                    this.formsectionData.xqId = this.formPush.xqId;
                    this.selecthouse = true;
                } else {
                    this.$message("请先选择项目！")
                    return
                }
                sectionList(this.formsectionData).then((res) => {//区域列表
                    //console.log(res)
                    if (res.data.ok) {
                        this.sectionData = res.data.data.records.filter((item) => {
                            if (item.gmtModified) {
                               // item.gmtModified = this.$root.getDateArray(item.gmtModified)[9]
                            }
                            return item
                        })
                        this.total1 = res.data.data.total
                        this.pages1 = res.data.pages
                    } else {
                        this.$message(res.data.msg);
                    }
                })
            },

            rowClick(row, column) {
                if (row.name) {
                    this.formhouseData.sectionName = row.name;
                    this.formhouseData.xqId = this.formPush.xqId;
                    this.gethouselist();
                }
            },
            gethouselist() {
                // //console.log("zzzzzzzzzzzzzzzz");
                if (this.formhouseData.sectionName) {
                    this.formhouseData.xqId = this.formPush.xqId;

                    houseList(this.formhouseData).then((res) => {//更具区域名称查房间列表
                        //console.log(res)
                        if (res.data.ok) {
                            this.houseData = res.data.data.records.filter((item) => {
                                if (item.gmtModified) {
                                   // item.gmtModified = this.$root.getDateArray(item.gmtModified)[9]
                                }
                                return item
                            })
                            this.total2 = res.data.data.total
                            this.pages2 = res.data.pages
                        } else {
                            this.$message(res.data.msg);
                        }
                    })
                }
            },

            rowhouseClick(row, column) {
                //console.log("rowhouse:", row)
            },
            handleCurrentPage1(val) {//页码区域改变
                this.formsectionData.current = val
                this.getsectionList()
            },
            handleCurrentPage2(val) {//页码区域改变
                this.formhouseData.current = val
                this.gethouselist()
            },
            closeqyfj() {
                this.formhouseData = {
                    current: 1,
                    size: 5
                }
            },

            //修改
            updatewllist(row, index) {
                let params = {
                    xqId: row.xqId
                }
                getDeviceClassifyXq(params).then((res) => {//设备类别
                    //console.log(res)
                    if (res.data.ok) {
                        this.sbtypeTree = res.data.data
                    }
                    //console.log( this.sbtypeTree);
                    let treeDef = this.get_OrganizationId2(
                        row.classifyId,
                        this.sbtypeTree,
                        "cascader"
                    )
                    this.option1 = treeDef;
                    //console.log("回填",this.option1);
                    //console.log("this.sbtypeTree", this.sbtypeTree)
                })

                this.formPush = {
                    xqId: row.xqId,
                    vender: row.vender,
                    supplierPhone: row.supplierPhone,
                    supplierName: row.supplierName,
                    startTime: row.startTime,
                    scrapTime: row.scrapTime,
                    remark: row.remark,
                    principal: row.principal,
                    picture: row.picture,
                    number: row.number,
                    name: row.name,
                    model: row.model,
                    installationDate: row.installationDate,
                    classifyId: row.classifyId,
                    namehouse: row.installationSite
                }
                if (row.houseId != '') {
                    this.formPush.houseId = row.houseId
                    this.formPush.sectionId = row.sectionId
                } else {
                    this.formPush.sectionId = row.sectionId
                    this.formPush.houseId = ''
                }
                if (index == 2) {
                    this.formPush.id = row.id
                }

                this.imageUrl = row.picture
                this.Addoredit = index
                this.adddialog = true



            },


            //以区域id查物品类别
            wptypeChange(value) {//改变组织
                this.$refs.cascader.dropDownVisible = false;
                if (value.length != 0) {
                    console.log(value)
                    this.zijiid = this.$refs.cascader.getCheckedNodes()[0].data.id
                    //this.parentId = this.$refs.cascader.getCheckedNodes()[0].data.parentId
                    console.log("option1", this.option1)
                    this.formPush.classifyId = this.zijiid
                    console.log(this.formPush.classifyId);
                } else {
                    this.zijiid = ''
                    this.formPush.classifyId = ''
                    //console.log(this.formPush.classifyId);
                }
            },

            wptypeChange3(value) {//改变类别
                this.$refs.cascader.dropDownVisible = false;
                if (value.length != 0) {
                    //console.log(value)
                    this.zijiid = this.$refs.cascader.getCheckedNodes()[0].data.id
                    this.parentId = this.$refs.cascader.getCheckedNodes()[0].data.parentId
                    //console.log("子id", this.zijiid)
                    //console.log("父id", this.parentId)
                } else {
                    this.zijiid = ''
                }
            },



            //添加
            addList() {
                console.log("this.formPush", this.formPush)
                this.$refs.addsbform.validate((valid) => {
                    // console.log("valid", valid)
                    if (valid) {
                        if (this.formPush.installationDate) {

                            //console.log(this.formPush.installationDate);
                            let anzhuangtime = new Date(this.formPush.installationDate).getTime()
                            this.formPush.installationDate = anzhuangtime;

                        }
                        if (this.formPush.startTime) {
                            ////console.log(this.formPush.startTime);
                            let startTime = new Date(this.formPush.startTime).getTime()
                            this.formPush.startTime = startTime;
                        }
                        if (this.formPush.scrapTime) {
                            ////console.log(this.formPush.scrapTime);
                            let scrapTime = new Date(this.formPush.scrapTime).getTime()
                            this.formPush.scrapTime = scrapTime;
                        }
                        if (this.formPush.classifyId == '') {
                            this.$message("设备类别不能为空！")
                            return
                        }
                        if (this.formPush.picture == '') {
                            this.$message("图片不能为空！")
                            return
                        }


                        this.$confirm("确定要执行此操作吗？", '提示', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            delete this.formPush.namehouse
                            //
                            //this.adddialog = false
                            console.log(this.formPush, 'hahahaha')
                            if (this.Addoredit == 1) {
                                addDeviceOperations(this.formPush).then((res) => {
                                    //console.log("新增", res)
                                    if (res.data.ok) {
                                        this.$message({
                                            message: '添加成功',
                                            type: 'success'
                                        });
                                        this.getlist()
                                        console.log(this.formPush, '11');

                                        //this.$refs.addsbform.resetFields();
                                        console.log(this.formPush, '22');
                                    } else {
                                        this.$message('添加失败')
                                    }
                                    this.adddialog = false
                                })
                            }
                            if (this.Addoredit == 2) {
                                updDeviceOperations(this.formPush).then((res) => {
                                    //console.log("新增", res)
                                    if (res.data.ok) {
                                        this.$message({
                                            message: '修改成功',
                                            type: 'success'
                                        });
                                        this.getlist()
                                        //this.formPush = {}
                                        this.$refs.addsbform.resetFields();
                                    } else {
                                        this.$message('修改失败')
                                    }
                                    this.adddialog = false
                                })
                                // console.log(this.formPush);
                                // this.$message('还没有修改接口！')
                                // this.adddialog = false
                            }

                            //this.adddialog = false

                        }).catch(_ => { })

                    } else {
                        //console.log('error submit!!');
                        return false;
                    }
                });
            },


            getlist() {
                getDevOperationsList(this.formSearch).then((res) => {//查询设备管理列表
                    console.log("设备管理列表:", res)
                    if (res.data.ok) {
                        this.formData = res.data.data.records.filter((item) => {
                            if (item.installationDate) {
                             //   item.installationDate = this.$root.getDateArray(item.installationDate)[9]
                            }
                            return item
                        })
                        this.total = res.data.data.total
                    } else {
                        this.$message(res.data.msg);
                    }
                })
            },


            handleCurrentPage(val) {//页码改变
                this.formSearch.current = val
                this.getlist()
            },

            getInit() {//初始化列表

                let org_tree1 = {
                    name: '',
                    status: 1
                }
                orgTree(org_tree1).then((res) => {//获取组织列表
                    //console.log(res)
                    if (res.data.ok) {
                        this.dataTree = res.data.data
                    }
                })


                xqSelectList({}).then((res) => {//区域选择列表
                    //console.log(res)
                    if (res.data.ok) {
                        this.xqTree1 = res.data.data
                    }
                })



                this.getlist();
            },

        },
        mounted() {
            this.getInit();
        },
        components: {
            paging,
            //   paging1
        }
    }
</script>
<style scoped>
    .hide.el-upload--picture-card {
        display: none;
    }

    .gridContt {
        line-height: 30px;
    }

    .xiangqingdialog.el-row {
        height: 26px;
    }

    .codediv {
        margin: 20px 0;
        text-align: center;
    }

    .shouquan {
        text-align: center;
        color: black;
        background: #fff;
        padding: 50px 0;
    }

    .qrcode {
        display: inline-block;
    }

    .el-table--scrollable-y .el-table__body-wrapper {
        /* overflow-y: auto; */
    }

    .el-table__fixed-right-patch {
        position: absolute;
        /* top: -1px; */
        right: 0;
        /* background-color: #FFF; */
    }

    /* .formpush >>> */
</style>
